<template>
  <div class="authentication">
    <div class="renzhengbox bg_colorff t_center" v-if="renzhengshow">
        <img class="head_img" src="../../assets/img/header.png"/>
        <div class="sf font_size32 color_33">身份： 学生</div>
        <div class="font_size24" :class="[is_adopt==0? 'color_fc': is_adopt==1? 'color_0d': is_adopt==2?'color_fc':is_adopt== 3? 'color_99': '']">状态：
          {{is_adopt==0? "待审核": is_adopt==1? "通过认证": is_adopt==2?"已驳回":is_adopt==3? '未认证':''}}</div>
        <div class="shenqbtn" v-if="is_adopt == 3 || is_adopt == 2" @click="gorenzFn">{{is_adopt==3? '申请认证': '从新认证'}}</div>
    </div>
    <div v-if="renzheng">
      <div class="studentinfo bg_colorff m_t20 p_r30 p_l30 p_b20">
        <div class="flex border_b p_r30 line90 font_size32 color_33">
          <div class="lable">学生证号</div>
          <div><input v-model="student_num" class="font_size32" type="text" maxlength="20" placeholder="学生证号"/></div>
        </div>
        <div class="flex border_b p_r30 line90 font_size32 color_33">
          <div class="lable">学校名称</div>
          <div><input v-model="school_name" class="font_size32" type="text" maxlength="20" placeholder="学校名称"/></div>
        </div>
        <div class="p_r30 line90 font_size24 color_33">上传证件</div>
        <div class="upschool_img t_center m_b20" style="position: relative">
          <input class="inputchoose" @change='chooseimgFn' type="file" id="choose1"  accept="image/png,image/jpeg,image/gif,image/jpg" ref="inputer"/>
          <div v-if="!img1"  style="position: absolute;width: 100%;height: 150px;text-align: center;top: 0px;">
            <img class="up_img" src="../../assets/img/upphone.png" height="80" width="93"/>
            <div class="m_t20 font_size24 color_99">上传证件照片（照片那一页）</div>
          </div>
          <div v-if="img1"><img class="upimg" :src="img1"/></div>
        </div>
      </div>
      <div class="studentinfo bg_colorff m_t20 p_r30 p_l30 p_b20">
        <div class="flex border_b p_r30 line90 font_size32 color_33">
          <div class="lable">身份证号</div>
          <div><input v-model="cordnum" class="font_size32" type="text" maxlength="18" placeholder="身份证号"/></div>
        </div>
        <div class="flex border_b p_r30 line90 font_size32 color_33">
          <div class="lable">真实姓名</div>
          <div><input v-model="username" class="font_size32" type="text" maxlength="10" placeholder="真实姓名"/></div>
        </div>
        <div class="p_r30 line90 font_size24 color_33">上传证件</div>
        <div class="upschool_img t_center m_b20" style="position: relative">
          <!--<input class="inputchoose" @change='chseimgFn' type="file" id="choose2" capture="camera" accept="image/png,image/jpeg,image/gif,image/jpg" ref="inputer"/>-->
          <input class="inputchoose" @change='chseimgFn' type="file" id="choose2"  accept="image/png,image/jpeg,image/gif,image/jpg" ref="inputer"/>
          <div v-if="!img2"  style="position: absolute;width: 100%;height: 150px;text-align: center;top: 0px;">
            <img class="up_img" src="../../assets/img/upphone.png" height="80" width="93"/>
            <div class="m_t20 font_size24 color_99">上传身份证正面</div>
          </div>
          <div v-if="img2"><img class="upimg" :src="img2"/></div>
        </div>
        <div class="upschool_img t_center m_b20" style="position: relative">
          <input class="inputchoose" @change='chooseimgFn' type="file" id="choose3"  accept="image/png,image/jpeg,image/gif,image/jpg" ref="inputer"/>
          <div v-if="!img3"  style="position: absolute;width: 100%;height: 150px;text-align: center;top: 0px;">
            <img class="up_img" src="../../assets/img/upphone.png" height="80" width="93"/>
            <div class="m_t20 font_size24 color_99">上传身份证背面</div>
          </div>
          <div v-if="img3"><img class="upimg" :src="img3"/></div>
        </div>
      </div>

      <div class="p_l30 p_r30"><div class="btn" @click="keepFn">提交</div></div>
    </div>


  </div>
</template>

<script>
    export default {
      name: "Authentication",
      data(){
        return{
          student_num: '',
          school_name: '',
          cordnum: '',
          username: '',
          formData:new FormData(),
          imgs: {},
          imgLen:0,
          img1: '',
          img2: '',
          img3: '',
          img_id1: '',
          img_id2: '',
          img_id3: '',
          is_adopt: '',
          renzhengshow: true,
          renzheng: false,
        }
      },
      created(){
        this.getproveFn()
        // this.chseimgFn()
      },
      methods: {
        getproveFn(){
          this.$util.get('user/getIdentityList',{
            uid: this.$store.state.userinfo.uid
          }).then(data => {
            if(data.status == 1){
            this.is_adopt = data.data.status
            }
          })
        },
        gorenzFn(){
          this.renzhengshow = !this.renzhengshow
          this.renzheng = !this.renzheng
        },
        chseimgFn(){
          alert('>>111>>:'+data)
          wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (data) {
              var localIds = data.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
              console.log(data)
              wx.uploadImage({
                localId: localIds[0], // 需要上传的图片的本地ID，由chooseImage接口获得
                isShowProgressTips: 1, // 默认为1，显示进度提示
                success: function (res) {
                  console.log('>>>'+res)
                  alert('>>>'+res)
                  var serverId = res.serverId; // 返回图片的服务器端ID
                }
              });


            }
          });
        },

        chooseimgFn(e) {
          console.log(e)
          console.log(e.target.files[0])
          console.log(e.target.id)
          var that = this;
          var file = e.target.files[0];
          // var imgSize = file.size / 1024;
          // if (imgSize > 200) {
          //   alert('请上传大小不要超过200KB的图片')
          // } else {
            var reader = new FormData();
            reader.append('img', file)
            console.log(reader)

            // 下面逻辑处理
            that.$util.formdataPost('/file/upload', reader).then(res => {
              console.log(res)
              if(res.status == 1){
                if (e.target.id == 'choose1') {
                  console.log(1)
                  this.img_id1 = res.data.id
                  that.img1 = res.data.domain + res.data.path
                }
                if (e.target.id == 'choose2') {
                  console.log(1)
                  this.img_id2 = res.data.id
                  that.img2 = res.data.domain + res.data.path
                }
                if (e.target.id == 'choose3') {
                  console.log(1)
                  this.img_id3 = res.data.id
                  that.img3 = res.data.domain + res.data.path
                }
              }
              });

          // }
          ;
        },

        keepFn() {
          var self = this
          if (!self.student_num) {
            this.$toast('请输入学生证号')
            return
          }
          if (!self.school_name) {
            this.$toast('请输入学校名称')
            return
          }
          if (!self.cordnum) {
            this.$toast('请输入身份证号')
            return
          }
          if (!self.username) {
            this.$toast('请输入真是姓名')
            return
          }
          if(!self.img1){
            this.$toast('请上传证件照片')
            return
          }
          if(!self.img2){
            this.$toast('请上传身份证正面照片')
            return
          }
          if(!self.img3){
            this.$toast('请上传身份证反面照片')
            return
          }

          self.$util.post('user/postUserAddProve',{
            id: '0',
            uid: self.$store.state.userinfo.uid,
            student_card: self.student_num,
            name: self.username,
            school_name: self.school_name,
            id_card: self.cordnum,
            student_img: this.img_id1,
            card_img: this.img_id2+','+this.img_id3
          }).then(data => {
              if(data.status == 1){
                this.$toast('审核认证提交成功！')
              }
            self.renzhengshow = !self.renzhengshow
            self.renzheng = !self.renzheng
          })

        },
      }
    }
</script>

<style lang="less" scoped>
  @import "../../assets/css/center/authentication";
</style>
